package com.cloud.mall.result;

import com.cloud.mall.exp.CustomException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author: 梁二东
 * @Date: 2024/12/9 13:52
 * @Description:
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExceptionResponse {

    /**
     * 异常码
     */
    private Integer code;

    /**
     * 已知的异常信息
     */
    private String message;

    /**
     * 请求url
     */
    private String path;

    /**
     * get,post,...
     */
    private String method;

    public static ExceptionResponse fail(CustomException exp) {
        ExceptionResponse result = new ExceptionResponse();
        result.setCode(exp.getCode());
        result.setMessage(exp.getMessage());
        result.setPath(exp.getPath());
        result.setMethod(exp.getMethod());
        return result;
    }
    public static ExceptionResponse fail(CustomException exp, String path, String method) {
        ExceptionResponse result = new ExceptionResponse();
        result.setCode(exp.getCode());
        result.setMessage(exp.getMessage());
        result.setPath(path);
        result.setMethod(method);
        return result;
    }
}
